package org.smile.homework01.arthas.oneCase;

public class Aircraft {

    public Aircraft(int engineNumber) {
        this.engines = new Engine[engineNumber];
        for (int i = 0; i < engines.length; i++) {
            this.engines[i] = new Engine(i);
            this.engines[i].describe();
        }
    }

    //1.需求3个引擎
    private final Engine[] engines;

    //2.运行成员函数
    public void start() {
        int workingEngine = 0;  //0,1,2
        boolean isWork;
        while (true) {
            isWork = false;

            //某一时刻的同时操作
            for (Engine engine : engines) {
                isWork = isWork || engine.isStandby();

                if (engine.isAvailable(workingEngine)) {
                    engine.run();
                    workingEngine = engine.next() % engines.length;  // 5 % 5  = 0
                } else {
                    engine.prepare();
                }

//                if (i == 0) {
//                    engine.run();
//                } else if (i == 1) {
//                    engine.cold();
//                } else if (i == 2) {
//                    engine.cold();
//                }

            }

            if(!isWork){
                System.out.println("飞行器不能运行。");
                break;
            }

//            this.engines[0].run();
//
//            this.engines[0].cold();
//            this.engines[1].run();
//
//            this.engines[1].cold();
//            this.engines[2].run();
//
//            this.engines[2].cold();

        }
    }
}
